package com.hwadee.JPKC.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hwadee.JPKC.entity.conmment;
import com.hwadee.JPKC.entity.courseInfo;
import com.hwadee.JPKC.entity.courseView;
import com.hwadee.JPKC.entity.user;
import com.hwadee.JPKC.service.ConmmentService;
import com.hwadee.JPKC.service.CourseInfoService;
import com.hwadee.JPKC.service.courseViewService;

/*
 * 评论控制
 */
@Controller
@RequestMapping("/Conmment")
public class ConmmentController {
	
	@Autowired
	private CourseInfoService courseInfoService;
	@Autowired
	private courseViewService courseviewservice;
	@Autowired
	private ConmmentService conmmentservice;
	
	/*
	 * 用户评论控制
	 */
	@PostMapping("/pinglun")
	public String pinglun(Integer courseId,conmment conmment,Model model,HttpServletRequest request,HttpSession session) {

		user u  = (user)session.getAttribute("u");
		System.out.println(u.toString());
		if(u.getUserRole().equals("专家")) {
			int num = conmmentservice.insert(conmment);
			System.err.println(num);
			String url="redirect:/Info/courseInfos?courseId="+courseId;
			return url;
		}else{
			session.setAttribute("errorMsg", "老师不能评论");
			String url="redirect:/Info/courseInfos?courseId="+courseId;
			return url;

		}		
	
	}
	
}
